package cn.sinata.wanglin.db;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

/**
 * Created by liaoxiang on 17/1/3.
 */

public class DbUtils {

    public static boolean isTableExist(SQLiteDatabase db,String tableName){
        if (db==null || !db.isOpen()) {
            return false;
        }
        boolean result = false;
        if (tableName == null) {
            return false;
        }
        Cursor cursor = null;
        try {
            String sql = "select count(*) as c from Sqlite_master  where type ='table' and name ='"
                    + tableName.trim() + "' ";
            cursor = db.rawQuery(sql, null);
            if (cursor.moveToNext()) {
                int count = cursor.getInt(0);
                if (count > 0) {
                    result = true;
                }
            }

        } catch (Exception e) {
        }finally {
            if (cursor != null) {
                cursor.close();
            }
        }
        return result;
    }
}
